<template>
    <div class="login">
        <mt-spinner type="triple-bounce"></mt-spinner>
       <p>正在登陆</p>
    </div>
</template>

<script>
    export default {
        name: "login",
        methods(){
           //  getUrlParam(name) {
           //      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
           //      var r = window.location.search.substr(1).match(reg);
           //      if (r != null) return unescape(r[2]);
           //     return null;
           // }
        },
        beforeCreate (){
            console.log(this.$route.meta);
            console.log(8899);
            const appId = 'wx81243217748ce054';
            const oauth_url = 'https://www.lyuanbo.club/v1/login/code';
            const url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appId + "&redirect_uri=" + location.href.split('#')[0] + "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
            const code = this.$options.methods.getUrlParam("code");
            if(!code){
                window.location = url ;

            }else {
                let [res,err]=this.to(this.getUrl("home/addr_list",{}))
                if (err===null){

                } else {

                }
                console.log('*******');
                console.log(code);
                console.log('*******');
                this.$http.get(oauth_url, {params: {code: code}}).then(res => {
                   // success callback
                   localStorage.setItem('loginMessage',JSON.stringify(res.data.data))
                   console.log(200);
               }, err => {
                   // error callback
                   console.log(4044);
               });



            }

        }
    }
</script>

<style scoped lang="less" rel="stylesheet/less">
    @import "../../lib/less/variable";
    .logon{
        width: 100%;
        text-align: center;
    }
</style>